/*
 * @Author: your name
 * @Date: 2021-06-06 22:16:12
 * @LastEditTime: 2021-06-16 17:22:39
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \CPP\UDP\client.cpp
 */
//c++头文件
#include<iostream>
using namespace std;
#include "guide.h"
#include "clientsocket.h" 
#include "manager.h"
#include "case.h"

int main(int argc, char * argv[])
{
	//判断参数数目
	if(argc != 3)
	{
		cout << "参数数目错误" << endl;
		return -1;
	}

	//创建udp通信
	ClientSocket c_socket(argv[2],argv[1]);
	
	//创建用户对象
	Manager um;
	//创建引导栏对象
	Guide guide;
	//case选项
	int choice;
    while (1)
    {
		//初始界面引导信息
		guide.initial_Guide();
		cout << "请输入你的选择:" << endl;
		choice = um.input_Choice();
	
		switch (choice)
		{
		case REGISTER:
			um.regist(c_socket);
			break;
		case LOGIN:
			um.login(c_socket);
			break;
		case U_SHOW_PRODUCTS:
			um.show_Commodity(c_socket);
			break;
		case EXIT:
			um.exit_exe();
			break;
		default:
			break;
		}


		//消费者登录界面
		while(um.get_Login_Statu() && um.get_User_Type() == CONSUMER)
		{
			//欢迎界面
			guide.consumer_Guide();
			cout << "请输入你的选择:" << endl;
			choice = um.input_Choice();

			switch (choice)
			{
			case SHOW_PRODUCTS:
				um.show_Commodity(c_socket);
				break;
			case RETRIEVE_PRODUCTS:
				um.search_Commodity(c_socket);
				break;
			case ADD_CART:
				um.add_Cart(c_socket);
				break;
			case MODIFY_CART:
				um.modify_Cart(c_socket);
				break;
			case SHOW_CART:
				um.show_Cart(c_socket);
				break;
			case CREATE_ORDER:
				um.create_Order(c_socket);
				break;
			case CHECK_BALANCE:
				um.show_Balance();
				break;
			case RECHARGE_BALANCE:
				um.recharge_Amount(c_socket);
				break;
			case CHANGE_PASSWD:
				um.change_Passwd(c_socket);
				break;
			case LOGOUT:
				um.logout();
				break;
			default:
				cout << "非法输入" << endl;
				break;
			}
			cin.get();
			system("clear");
		}

		//商家登录界面
		while(um.get_Login_Statu() && um.get_User_Type() == MERCHANT)
		{
			guide.merchant_Guide();
			cout << "请输入你的选择:" << endl;
			choice = um.input_Choice();
			switch(choice)
			{
			case M_SHOW_PRODUCTS:
				um.show_Commodity(c_socket);
				break;
			case M_RETRIEVE_PRODUCTS:
				um.search_Commodity(c_socket);
				break;
			case M_ADD_PRODUCTS:
				um.add_Commodity(c_socket);
				break;
			case M_MODIFY_PRODUCTS:
				um.modify_Commodity(c_socket);
				break;
			case M_CHECK_BALANCE:
				um.show_Balance();
				break;
			case M_LOGOUT:
				um.logout();
				break;
			default:
				cout << "非法输入" << endl;
				break;
			}
			cin.get();
			system("clear");
		}
		cin.get();
		system("clear");
    }


    return 0;
}